package com.school.entity;

import com.school.course.Course;

public class Student extends Person {
    // 特有属性：所选课程
    private Course selectedCourse;

    // 子类构造方法：super()初始化父类属性
    public Student(String studentId, String studentName, String gender) {
        super(studentId, studentName, gender);
    }

    // 特有业务方法1：选课
    public void selectCourse(Course course) {
        if (this.selectedCourse != null) {
            System.out.println("学生[" + super.name + "]已选课程[" + selectedCourse.getCourseName() + "]，不可重复选课");
        } else {
            this.selectedCourse = course;
            System.out.println("学生[" + super.name + "]成功选修课程[" + course.getCourseName() + "]");
        }
    }

    // 特有业务方法2：退课
    public void dropCourse() {
        if (this.selectedCourse == null) {
            System.out.println("学生[" + super.name + "]未选任何课程，无需退课");
        } else {
            System.out.println("学生[" + super.name + "]成功退选课程[" + selectedCourse.getCourseName() + "]");
            this.selectedCourse = null;
        }
    }

    // 特有业务方法3：打印课表（父类printInfo的扩展场景）
    public void printSchedule() {
        System.out.println("\n===== 学生[" + super.name + "]课表 =====");
        if (this.selectedCourse == null) {
            System.out.println("当前未选修任何课程");
        } else {
            Course course = this.selectedCourse;
            System.out.println("课程编号：" + course.getCourseId());
            System.out.println("课程名称：" + course.getCourseName());
            System.out.println("上课地点：" + course.getLocation());
            System.out.println("上课时间：" + course.getTime());
            System.out.println("课程学分：" + course.getCredit());
            System.out.println("授课教师：" + course.getTeacher().getName()); // 跨类调用Teacher的getName()
        }
        System.out.println("=============================\n");
    }

    // 重写父类方法：扩展为“打印学生信息+选课状态”
    @Override
    public void printInfo() {
        super.printInfo();
        if (selectedCourse != null) {
            System.out.println("选课状态：已选[" + selectedCourse.getCourseName() + "]");
        } else {
            System.out.println("选课状态：未选课");
        }
    }

    // Getter：供外部访问所选课程
    public Course getSelectedCourse() {
        return selectedCourse;
    }
}